<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>会员管理</title>
  <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
  <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
  <link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
  <link rel="stylesheet" href="../css/style.css">
  <script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
  <script src="../plugins/bootstrap/js/bootstrap.min.js"></script>


</head>
<body class="hold-transition skin-red sidebar-mini">
<!-- .box-body -->
<div class="box-header with-border">
  <h3 class="box-title">会员管理</h3>
</div>

<div class="box-body">

  <!-- 数据表格 -->
  <div class="table-box">

    <!--工具栏-->
    <div class="pull-left">
      <div class="form-group form-inline">
        <div class="btn-group">
          <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
        </div>
      </div>
    </div>
    <div class="box-tools pull-right">
      <div class="has-feedback">

      </div>
    </div>
    <!--工具栏/-->

    <!--数据列表-->
    <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
      <thead>
      <tr>
        <th class="" style="padding-right:0px">
          <input id="selall" type="checkbox" class="icheckbox_square-blue">
        </th>
        <th class="sorting_asc">用户ID</th>
        <th class="sorting">用户手机号</th>
        <th class="sorting">用户名称</th>
        <th class="sorting">性别</th>
        <th class="sorting">出生日期</th>
        <th class="sorting">支付宝账号</th>
        <th class="sorting">注册时间</th>
        <th class="sorting">更新时间</th>
        <th class="sorting">状态</th>
        <th class="text-center">操作</th>
      </tr>
      </thead>
      <tbody id="table">
      </tbody>
    </table>
    <!--数据列表/-->


  </div>
  <!-- 数据表格 /-->




</div>
<!-- /.box-body -->
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" >
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">会员编辑</h3>
      </div>
      <div class="modal-body">
        <table class="table table-bordered table-striped"  width="800px">
          <tr>
            <td>用户手机号</td>
            <td>
              <input  type="hidden" class="form-control" placeholder="id" name="id" id="userId">
              <input  type="text" class="form-control" placeholder="用户手机号" name="telephone" id="telephone">  </td>
          </tr>
          <tr>
            <td>用户名称</td>
            <td><input type="text" class="form-control" placeholder="用户名称" name="name" id="name">  </td>
          </tr>
          <tr>
            <td>性别</td>
            <td><input type="text" class="form-control" placeholder="性别" name="sex" id="sex">  </td>
          </tr>
          <tr>
            <td>出生日期</td>
            <td><input type="text" class="form-control" placeholder="出生日期" name="birthday" id="birthday">  </td>
          </tr>
          <tr>
            <td>支付宝账号</td>
            <td><input type="text" class="form-control" placeholder="支付宝账号" name="alipayAccount" id="alipayAccount">  </td>
          </tr>
          <tr>
            <td>注册时间</td>
            <td><input type="text" class="form-control" placeholder="注册时间" name="createTime" id="createTime">  </td>
          </tr>
          <tr>
            <td>更新时间</td>
            <td><input type="text" class="form-control" placeholder="更新时间" name="updateTime" id="updateTime">  </td>
          </tr>
          <tr>
            <td>状态</td>
            <td><input type="text" class="form-control" placeholder="状态" name="status" id="status">  </td>
          </tr>
        </table>
      </div>
      <div class="modal-footer">
        <button class="btn btn-success" data-dismiss="modal" aria-hidden="true" onclick="updateById()">保存</button>
        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
      </div>
    </div>
  </div>
</div>


</body>
<script type="text/javascript">


  $(function () {
    getUser();
  });

  function getUser() {
    $.ajax({
      url: "/user/getUserInfo" ,
      type: "post",
      data: {},
      dataType: "json",
      async: false,
      success: function (result) {
        if(result.code == 200){
          var list = result.data;
          var info = "";
          $(list).each(function (i,e) {
            info += "<tr>";
            info += '<td><input  type="checkbox" value="'+e.id+'" name="box"></td>';
            info += '<td>'+e.id+'</td>';
            info += '<td>'+e.telephone+'</td>';
            info += '<td>'+e.name+'</td>';
            if(e.sex == 1){
              info +='<td>男</td>';
            }else {
              info +='<td>女</td>';
            }
            info += '<td>'+e.birthday+'</td>';
            info += '<td>'+e.alipayAccount+'</td>';
            info += '<td>'+e.createTime+'</td>';
            info += '<td>'+e.updateTime+'</td>';
            if(e.status == 1){
              info +='<td>活着</td>';
            }else{
              info +='<td>注销</td>';
            }
            info += '<td class="text-center">';
            info += '<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal"  onclick="updateUser('+e.id+')">修改</button>';
            info += '</td>';
            info += '</tr>';
          });
          $("#table").html(info);
        }

      },
      error: function () {
        alert("系统异常,请联系管理员");
      }
    })
  }


  function updateUser(id) {
    $.ajax({
      url: "/user/toUpdate/"+id,
      type: "post",
      data: {},
      dataType: "json",
      async: false,
      success: function (result) {
        if(result.code == 200){
          var user = result.data;
          $("#userId").val(user.id);
          $("#telephone").val(user.telephone);
          $("#name").val(user.name);
          $("#sex").val(user.sex);
          $("#birthday").val(user.birthday);
          $("#alipayAccount").val(user.alipayAccount);
          $("#createTime").val(user.createTime);
          $("#updateTime").val(user.updateTime);
          $("#status").val(user.status);
        }
      },
      error: function () {
        alert("系统异常,请联系管理员");
      }
    })
  }

  function updateById() {
    $.ajax({
      url: "/user/updateUserInfo/",
      type: "post",
      contentType: 'application/json; charset=UTF-8',
      data: JSON.stringify({id: $("#userId").val(),telephone:$("#telephone").val(),name:$("#name").val(),sex:$("#sex").val(),birthday:$("#birthday").val(),
        alipayAccount:$("#alipayAccount").val(),createTime:$("#createTime").val(),
        updateTime:$("#updateTime").val(),status:$("#status").val()

      }),
      dataType: "json",
      async: false,
      success: function (result) {
        if(result.code == 200){
          window.location.reload();
        }

      },
      error: function () {
        alert("系统异常,请联系管理员");
      }
    })

  }

</script>
</html>